#!/bin/bash
#
# Configure a Solr demo and then run solr in the foreground

set -e

if [[ "$VERBOSE" = "yes" ]]; then
    set -x
fi

. /opt/docker-solr/scripts/run-initdb

sentinel=/opt/docker-solr/demo_created
if [ -f $sentinel ]; then
  echo "skipping demo creation"
else
  CORE=demo
  start-local-solr
  echo "Creating $CORE"
  /opt/solr/bin/solr create -c "$CORE"
  echo "Created $CORE"
  echo "Loading example data"
  /opt/solr/bin/post -c $CORE example/exampledocs/*.xml
  /opt/solr/bin/post -c $CORE example/exampledocs/books.json
  /opt/solr/bin/post -c $CORE example/exampledocs/books.csv
  echo "Loaded example data"
  stop-local-solr
  touch $sentinel
fi

exec solr -f
